<template>
  <div>
    <div><BasicForm @register="register" /> </div>
    <div class="flex justify-center">
      <a-button @click="resetFields"> 重置 </a-button>
      <a-button class="!ml-4" type="primary" @click="handleSubmit"> 确认 </a-button>
    </div>
  </div>
</template>
<script lang="ts">
  import { defineComponent, useAttrs, onBeforeMount } from 'vue';
  import { formSchema } from './pwd.data';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { adminStore } from '/@/store/locality/admin';
  import { message } from 'ant-design-vue';
  // import { CollapseContainer } from '/@/components/Container/index';
  // import { useMessage } from '/@/hooks/web/useMessage';

  export default defineComponent({
    name: 'Register',
    components: { BasicForm },
    props: {
      pageList: {
        type: Object,
        return: {},
      },
    },
    setup(props, { emit }) {
      var adminstore = adminStore();

      const [register, { validate, resetFields }]: any = useForm({
        size: 'large',
        baseColProps: { span: 24 },
        labelWidth: 100,
        showActionButtonGroup: false,
        schemas: formSchema,
      });

      async function handleSubmit() {
        try {
          const values = await validate();
          // const { password } = values;
          const result: any = await adminstore.AccoutRegister(values);
          console.log(result);

          if (result == 200) {
            resetFields();
            message.success('注册成功!');
            emit('registerReturn', 'success');
          } else {
            message.success(result.message);
          }
        } catch (error) {
          console.log(error);
        }

        // createMessage.success('click search,values:' + JSON.stringify(values));
      }

      // 要register还没渲染就要把optios的值改变
      onBeforeMount(() => {
        // 接收参数
        const attrs = useAttrs();
        formSchema[1]['componentProps']['options'] = attrs.rolesList;
      });
      return {
        formSchema,
        resetFields,
        register,

        handleSubmit,
      };
    },
  });
</script>

<style></style>
